package collection;

import java.util.ArrayList;
import java.util.List;

/**
 * List获取子集操作
 *  subList(int fromIndex, int toIndex),含头不含尾
 */

public class ListDemo3 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i<10; i++){
            list.add(i*10);
        }
        System.out.println("list"+list);
        //获取下标3-7的元素
        List<Integer> subList = list.subList(3,8);
        System.out.println("subList"+subList);
        for(int i = 0;i<subList.size();i++){
            subList.set(i,subList.get(i)*10);

        }
        System.out.println("subList"+subList);
        System.out.println("list"+list);

        list.set(3,3000);
        System.out.println("list"+list);
        System.out.println("subList"+subList);
        list.remove(0);
        System.out.println("list"+list);
        //原集合的长度发生改变后，子集不能在进行任何操作，否则会发生异常，但可重新获取子集
    }
}
